
//
//  NearbyCell.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/8.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "NearbyCell.h"
#import "StringTool.h"
#import "config.h"


@interface NearbyCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *moreLab;
@property (weak, nonatomic) IBOutlet UIImageView *rightIconView;

@end


@implementation NearbyCell



+(instancetype) cellWithTableView:(UITableView *)tableview;
{
    static NSString *ID = @"NearbyCell";
    NearbyCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"NearbyCell" owner:nil options:nil]lastObject];
        
        [cell.titleLab setPreferredMaxLayoutWidth:61];
        [cell.titleLab layoutIfNeeded];
        
        [cell.moreLab setPreferredMaxLayoutWidth:PMW - 10 - 61-6-5-6-10];
        [cell.moreLab layoutIfNeeded];
    }
    
    return cell;
}


+(CGFloat)getHight:(NearbyCellData *)data withTableView:(UITableView *)tableView{
    
    static NearbyCell *cell = nil;
    
    static dispatch_once_t predicate; dispatch_once(&predicate, ^{
        
        cell = [NearbyCell cellWithTableView:tableView];
    });
    
    [cell setData:data];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

    return height+1;
}



-(void)setData:(NearbyCellData*)data{
    
    NSString *detail = data.detail;
    if (data.detail.length>33&&[data.title containsString:@"周边学校"]) {
        detail = [NSString stringWithFormat:@"%@...",[data.detail substringToIndex:33]];
    }
    
    [self.titleLab setText:data.title];
    
    [self.moreLab setText:detail];
    
    [self.rightIconView setHidden:data.moreDetial==nil];
    
    
    if ([StringTool isBlankString:data.moreDetial]) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
    }else{
        [self setSelectionStyle:UITableViewCellSelectionStyleGray];
    }
}





- (void)awakeFromNib {
    // Initialization code
}

@end
